package net.bsayiner.foreignExchange.Utilities;

import java.util.ArrayList;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class MetalReader {

	String urlText = "http://www.dovizxml.com/altin-fiyatlari.html";
	private ArrayList<Metal> metals;

	public MetalReader() {
		metals = new ArrayList<Metal>(12);
	}

	public ArrayList<Metal> getCurrenciesFromWeb() {
		try {
			Document document = Jsoup.connect(urlText).get();
			Elements info = document.select("span.kuralsatbaslik");
			for (int i = 7; i < info.size(); i += 6) {
				Metal metal = new Metal();
				metal.setGoldName(Jsoup.parse(info.get(i).toString()).text());
				metal.setBuying(Float.parseFloat(Jsoup.parse(info.get(i + 2).toString()).text().replace(",", "")));
				metal.setSelling(Float.parseFloat(Jsoup.parse(info.get(i + 4).toString()).text().replace(",", "")));
				metals.add(metal);
				System.err.println(i);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return metals;
	}

}
